package tjs.org.springLoader.config;

import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import tjs.org.springLoader.fileWatch.FileSystemWatcher;

public class RestartApplicationListener implements ApplicationListener<ContextRefreshedEvent> {

    private AutoReloaderProperties autoReloaderProperties;

    public RestartApplicationListener(AutoReloaderProperties autoReloaderProperties) {
        this.autoReloaderProperties = autoReloaderProperties;
    }

    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        DoAutoReloader doAutoReloader = new DoAutoReloader(event.getApplicationContext(), this.autoReloaderProperties);
        FileSystemWatcher fileSystemWatcher = new FileSystemWatcher(doAutoReloader);
        fileSystemWatcher.start();
    }
}